<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
 * Default Kohana controller. This controller should NOT be used in production.
 * It is for demonstration purposes only!
 *
 * @package    Core
 * @author     Kohana Team
 * @copyright  (c) 2007-2008 Kohana Team
 * @license    http://kohanaphp.com/license.html
 */
class Welcome_Controller extends Web_Controller {

	// Disable this controller when Kohana is set to production mode.
	// See http://docs.kohanaphp.com/installation/deployment for more details.
	const ALLOW_PRODUCTION = FALSE;

	// Set the name of the template to use
	public $template = 'kohana/template';

	public function index()
	{
		// In Kohana, all views are loaded and treated as objects.
		$this->template->content = new View('welcome_content'); 
		// You can assign anything variable to a view by using standard OOP
		// methods. In my welcome view, the $title variable will be assigned
		// the value I give it here.
		$this->template->title = '';;
		$this->selected_page = 'main';
		
		$adv = new Adv_Model();
		$this->template->content->adv = $adv->getContent();

                $this->already_been = cookie::get('already_been');

                if ($this->already_been != 1) {
                    cookie::set('already_been', 1);
                }

		$table = 'bz_news';
		$query = $this->db->select('nw_date, nw_link_local, nw_title')->from($table)->limit(5)->orderby('nw_date', 'desc')->orderby('nw_title')->get();

                 $this->template->content->news = array();

                foreach ($query as $item){

                        $this->template->content->news[] = $item;

                }

	}

  
} // End Welcome Controller